function UseForm() {
    layui.use('form', function() {})
}

function SubmitForm(formid, url, beforesubmit, params, callback) {
    var formvalidator = $("#" + formid).validate();
    if (formvalidator.form()) {
        var form = layui.form;
        var formData = form.val(formid);
        //合并表单数据和传递的额外参数，若key相同，以表单数据为准
        var postdata = {};
        if (params) {
            for (var attr in params) {
                postdata[attr] = params[attr];
            }
        }
        for (var attr in formData) {
            postdata[attr] = formData[attr];
        }
        if (beforesubmit) {
            if (beforesubmit(postdata)) {
                HttpPost(JSON.stringify(postdata), url, function(result, status) {
                    callback(result, status)
                })
            }
        } else {
            HttpPost(JSON.stringify(postdata), url, function(result, status) {
                callback(result, status)
            })
        }
    }
    return false;
}


function SetForm(formid, url, params, callback) {
    layui.use('form', function() {
        var form = layui.form;
        HttpPost(JSON.stringify(params), url, function(result, status) {
            if (result.code == 0) {
                form.val(formid, result.data.obj)
                if (callback) {
                    callback(result.data.obj);
                }
            } else {
                OpenFail(result.msg)
            }
        })
    });

}
